{
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "# 图形和坐标轴基础\n",
        "\n",
        "本教程将详细讲解 Matplotlib 中图形对象和坐标轴的基础操作，包括：\n",
        "1. 创建图形对象\n",
        "2. 坐标轴操作\n",
        "3. 图例和标注\n",
        "\n",
        "这些是 Matplotlib 绘图的基础，掌握这些知识对于创建专业的图表至关重要。\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {},
      "outputs": [],
      "source": [
        "# 导入必要的库\n",
        "import matplotlib.pyplot as plt\n",
        "import numpy as np\n",
        "\n",
        "# 设置中文字体（如果需要显示中文）\n",
        "plt.rcParams['font.sans-serif'] = ['Arial Unicode MS', 'SimHei', 'DejaVu Sans']\n",
        "plt.rcParams['axes.unicode_minus'] = False  # 解决负号显示问题\n",
        "\n",
        "# 在 Jupyter Notebook 中内联显示图形\n",
        "%matplotlib inline\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## 第一部分：创建图形对象\n",
        "\n",
        "### 1.1 plt.figure() 创建新图形\n",
        "\n",
        "`plt.figure()` 是创建新图形对象的基础函数。每次调用都会创建一个新的图形窗口。\n",
        "\n",
        "**基本语法**：\n",
        "```python\n",
        "plt.figure(figsize=None, dpi=None, facecolor=None, edgecolor=None, ...)\n",
        "```\n",
        "\n",
        "**参数说明**：\n",
        "- `figsize`: 图形大小，元组格式 `(width, height)`，单位为英寸\n",
        "- `dpi`: 分辨率（每英寸点数），默认通常为 100\n",
        "- `facecolor`: 图形背景颜色\n",
        "- `edgecolor`: 图形边框颜色\n",
        "- `frameon`: 是否显示边框，默认为 True\n",
        "- `num`: 图形编号或标题\n",
        "\n",
        "**返回值**：\n",
        "- 返回一个 `Figure` 对象，可以用于后续的图形操作\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {},
      "outputs": [],
      "source": [
        "# 示例 1：创建默认图形\n",
        "plt.figure()\n",
        "x = np.linspace(0, 10, 100)\n",
        "y = np.sin(x)\n",
        "plt.plot(x, y)\n",
        "plt.title('默认图形')\n",
        "plt.show()\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "### 1.2 figsize 参数：设置图形大小\n",
        "\n",
        "`figsize` 参数用于控制图形的宽度和高度，单位是英寸。\n",
        "\n",
        "**语法格式**：\n",
        "```python\n",
        "plt.figure(figsize=(width, height))\n",
        "```\n",
        "\n",
        "**常用尺寸**：\n",
        "- 默认：`(6.4, 4.8)` 英寸\n",
        "- 宽屏：`(12, 6)` 或 `(16, 9)`\n",
        "- 正方形：`(8, 8)`\n",
        "- 纵向：`(6, 10)`\n",
        "\n",
        "**注意事项**：\n",
        "- 第一个值是宽度，第二个值是高度\n",
        "- 单位是英寸，不是像素\n",
        "- 实际显示大小会受到 DPI 设置的影响\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {},
      "outputs": [],
      "source": [
        "# 示例 2：不同大小的图形对比\n",
        "fig, axes = plt.subplots(1, 3, figsize=(15, 4))\n",
        "\n",
        "x = np.linspace(0, 10, 100)\n",
        "y = np.sin(x)\n",
        "\n",
        "# 小图形\n",
        "axes[0].plot(x, y)\n",
        "axes[0].set_title('小图形 (4, 3)')\n",
        "axes[0].grid(True)\n",
        "\n",
        "# 中等图形\n",
        "axes[1].plot(x, y)\n",
        "axes[1].set_title('中等图形 (6, 4)')\n",
        "axes[1].grid(True)\n",
        "\n",
        "# 大图形\n",
        "axes[2].plot(x, y)\n",
        "axes[2].set_title('大图形 (10, 6)')\n",
        "axes[2].grid(True)\n",
        "\n",
        "plt.tight_layout()\n",
        "plt.show()\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "### 1.3 dpi 参数：设置分辨率\n",
        "\n",
        "`dpi`（dots per inch，每英寸点数）控制图形的分辨率，影响图形的清晰度和文件大小。\n",
        "\n",
        "**语法格式**：\n",
        "```python\n",
        "plt.figure(dpi=100)  # 默认通常是 100\n",
        "```\n",
        "\n",
        "**常用 DPI 值**：\n",
        "- 屏幕显示：72-100 DPI\n",
        "- 打印质量：150-300 DPI\n",
        "- 高质量打印：300+ DPI\n",
        "\n",
        "**注意事项**：\n",
        "- DPI 越高，图形越清晰，但文件也越大\n",
        "- 对于屏幕显示，100 DPI 通常足够\n",
        "- 保存图形时也可以单独设置 DPI：`plt.savefig('file.png', dpi=300)`\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {},
      "outputs": [],
      "source": [
        "# 示例 3：不同 DPI 的对比（注意：在 Notebook 中可能看不出明显区别）\n",
        "# 但保存为文件时会有明显差异\n",
        "\n",
        "x = np.linspace(0, 10, 100)\n",
        "y = np.sin(x)\n",
        "\n",
        "# 低分辨率\n",
        "plt.figure(figsize=(6, 4), dpi=50)\n",
        "plt.plot(x, y, linewidth=2)\n",
        "plt.title('低分辨率 (DPI=50)', fontsize=14)\n",
        "plt.grid(True, alpha=0.3)\n",
        "plt.show()\n",
        "\n",
        "# 高分辨率\n",
        "plt.figure(figsize=(6, 4), dpi=200)\n",
        "plt.plot(x, y, linewidth=2)\n",
        "plt.title('高分辨率 (DPI=200)', fontsize=14)\n",
        "plt.grid(True, alpha=0.3)\n",
        "plt.show()\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "### 1.4 facecolor 和 edgecolor：背景色和边框色\n",
        "\n",
        "这两个参数用于设置图形的背景颜色和边框颜色。\n",
        "\n",
        "**语法格式**：\n",
        "```python\n",
        "plt.figure(facecolor='white', edgecolor='black')\n",
        "```\n",
        "\n",
        "**颜色表示方法**：\n",
        "- 颜色名称：`'white'`, `'black'`, `'red'`, `'blue'` 等\n",
        "- 十六进制：`'#FFFFFF'`, `'#000000'` 等\n",
        "- RGB 元组：`(1.0, 1.0, 1.0)` 或 `(255, 255, 255)`\n",
        "- 灰度值：`'0.8'` 或 `0.8`（0-1之间）\n",
        "\n",
        "**使用场景**：\n",
        "- 创建深色主题的图表\n",
        "- 匹配报告或演示文稿的背景色\n",
        "- 创建特殊视觉效果\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {},
      "outputs": [],
      "source": [
        "# 示例 4：不同背景色的图形\n",
        "x = np.linspace(0, 10, 100)\n",
        "y = np.sin(x)\n",
        "\n",
        "# 白色背景（默认）\n",
        "plt.figure(figsize=(6, 4), facecolor='white', edgecolor='black', linewidth=2)\n",
        "plt.plot(x, y, 'b-', linewidth=2)\n",
        "plt.title('白色背景', fontsize=14, color='black')\n",
        "plt.grid(True, alpha=0.3)\n",
        "plt.show()\n",
        "\n",
        "# 浅灰色背景\n",
        "plt.figure(figsize=(6, 4), facecolor='lightgray', edgecolor='darkgray', linewidth=2)\n",
        "plt.plot(x, y, 'b-', linewidth=2)\n",
        "plt.title('浅灰色背景', fontsize=14, color='black')\n",
        "plt.grid(True, alpha=0.3)\n",
        "plt.show()\n",
        "\n",
        "# 深色背景\n",
        "plt.figure(figsize=(6, 4), facecolor='#2C3E50', edgecolor='white', linewidth=2)\n",
        "plt.plot(x, y, 'yellow', linewidth=2)\n",
        "plt.title('深色背景', fontsize=14, color='white')\n",
        "plt.grid(True, alpha=0.3, color='white')\n",
        "plt.gca().set_facecolor('#34495E')  # 设置坐标轴区域背景色\n",
        "plt.gca().tick_params(colors='white')  # 设置刻度颜色\n",
        "plt.gca().spines['bottom'].set_color('white')  # 设置坐标轴颜色\n",
        "plt.gca().spines['top'].set_color('white')\n",
        "plt.gca().spines['left'].set_color('white')\n",
        "plt.gca().spines['right'].set_color('white')\n",
        "plt.show()\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## 第二部分：坐标轴操作\n",
        "\n",
        "坐标轴操作是图表美化的关键部分，包括设置坐标轴范围、刻度、标签等。\n",
        "\n",
        "### 2.1 plt.xlim() 和 plt.ylim()：设置坐标轴范围\n",
        "\n",
        "这两个函数用于设置 x 轴和 y 轴的显示范围。\n",
        "\n",
        "**语法格式**：\n",
        "```python\n",
        "plt.xlim(left, right)  # 设置 x 轴范围\n",
        "plt.ylim(bottom, top)  # 设置 y 轴范围\n",
        "```\n",
        "\n",
        "**参数说明**：\n",
        "- `left/right`: x 轴的最小值和最大值\n",
        "- `bottom/top`: y 轴的最小值和最大值\n",
        "- 可以只设置一个值，另一个值保持自动：`plt.xlim(left=0)`\n",
        "\n",
        "**返回值**：\n",
        "- 返回当前坐标轴范围的元组：`(min, max)`\n",
        "\n",
        "**使用场景**：\n",
        "- 放大显示数据的特定区域\n",
        "- 统一多个子图的坐标轴范围\n",
        "- 创建特定比例的图表\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {},
      "outputs": [],
      "source": [
        "# 示例 5：设置坐标轴范围\n",
        "x = np.linspace(0, 10, 100)\n",
        "y = np.sin(x)\n",
        "\n",
        "# 自动范围（默认）\n",
        "plt.figure(figsize=(12, 4))\n",
        "plt.subplot(1, 2, 1)\n",
        "plt.plot(x, y, 'b-', linewidth=2)\n",
        "plt.title('自动范围（默认）', fontsize=14)\n",
        "plt.grid(True, alpha=0.3)\n",
        "\n",
        "# 手动设置范围\n",
        "plt.subplot(1, 2, 2)\n",
        "plt.plot(x, y, 'b-', linewidth=2)\n",
        "plt.xlim(2, 8)  # 只显示 x 从 2 到 8 的部分\n",
        "plt.ylim(-0.5, 0.5)  # 只显示 y 从 -0.5 到 0.5 的部分\n",
        "plt.title('手动设置范围', fontsize=14)\n",
        "plt.grid(True, alpha=0.3)\n",
        "\n",
        "plt.tight_layout()\n",
        "plt.show()\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "### 2.2 plt.axis()：一次性设置 x 和 y 轴范围\n",
        "\n",
        "`plt.axis()` 可以一次性设置 x 和 y 轴的范围，更加便捷。\n",
        "\n",
        "**语法格式**：\n",
        "```python\n",
        "plt.axis([xmin, xmax, ymin, ymax])  # 列表形式\n",
        "plt.axis('equal')  # 等比例坐标轴\n",
        "plt.axis('off')  # 关闭坐标轴\n",
        "plt.axis('tight')  # 紧凑模式\n",
        "plt.axis('auto')  # 自动模式（默认）\n",
        "```\n",
        "\n",
        "**常用模式**：\n",
        "- `'equal'`: x 和 y 轴使用相同的比例\n",
        "- `'scaled'`: 缩放坐标轴使图形填满显示区域\n",
        "- `'tight'`: 紧凑模式，去除多余的空白\n",
        "- `'auto'`: 自动调整（默认）\n",
        "- `'off'`: 关闭所有坐标轴和刻度\n",
        "- `'on'`: 显示坐标轴（默认）\n",
        "\n",
        "**返回值**：\n",
        "- 返回当前坐标轴范围的元组：`(xmin, xmax, ymin, ymax)`\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {},
      "outputs": [],
      "source": [
        "# 示例 6：plt.axis() 的不同用法\n",
        "x = np.linspace(0, 10, 100)\n",
        "y = np.sin(x)\n",
        "\n",
        "fig, axes = plt.subplots(2, 2, figsize=(12, 10))\n",
        "\n",
        "# 1. 手动设置范围\n",
        "axes[0, 0].plot(x, y, 'b-', linewidth=2)\n",
        "axes[0, 0].axis([2, 8, -0.5, 0.5])\n",
        "axes[0, 0].set_title('手动设置范围 [2, 8, -0.5, 0.5]', fontsize=12)\n",
        "axes[0, 0].grid(True, alpha=0.3)\n",
        "\n",
        "# 2. 等比例坐标轴（适合绘制圆形等）\n",
        "theta = np.linspace(0, 2*np.pi, 100)\n",
        "circle_x = np.cos(theta)\n",
        "circle_y = np.sin(theta)\n",
        "axes[0, 1].plot(circle_x, circle_y, 'r-', linewidth=2)\n",
        "axes[0, 1].axis('equal')\n",
        "axes[0, 1].set_title('等比例坐标轴 (equal)', fontsize=12)\n",
        "axes[0, 1].grid(True, alpha=0.3)\n",
        "\n",
        "# 3. 紧凑模式\n",
        "axes[1, 0].plot(x, y, 'g-', linewidth=2)\n",
        "axes[1, 0].axis('tight')\n",
        "axes[1, 0].set_title('紧凑模式 (tight)', fontsize=12)\n",
        "axes[1, 0].grid(True, alpha=0.3)\n",
        "\n",
        "# 4. 关闭坐标轴\n",
        "axes[1, 1].plot(x, y, 'm-', linewidth=2)\n",
        "axes[1, 1].axis('off')\n",
        "axes[1, 1].set_title('关闭坐标轴 (off)', fontsize=12)\n",
        "\n",
        "plt.tight_layout()\n",
        "plt.show()\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "### 2.3 plt.xticks() 和 plt.yticks()：设置刻度位置和标签\n",
        "\n",
        "这两个函数用于自定义坐标轴的刻度位置和标签。\n",
        "\n",
        "**语法格式**：\n",
        "```python\n",
        "plt.xticks(ticks, labels, rotation=0, ...)\n",
        "plt.yticks(ticks, labels, rotation=0, ...)\n",
        "```\n",
        "\n",
        "**参数说明**：\n",
        "- `ticks`: 刻度位置（列表或数组），如果为 None 则不改变位置\n",
        "- `labels`: 刻度标签（列表），如果为 None 则使用默认标签\n",
        "- `rotation`: 标签旋转角度（度数）\n",
        "- `fontsize`: 标签字体大小\n",
        "\n",
        "**常用操作**：\n",
        "- 只设置位置：`plt.xticks([0, 1, 2, 3])`\n",
        "- 设置位置和标签：`plt.xticks([0, 1, 2], ['A', 'B', 'C'])`\n",
        "- 旋转标签：`plt.xticks(rotation=45)`\n",
        "- 隐藏刻度：`plt.xticks([])` 或 `plt.xticks(visible=False)`\n",
        "\n",
        "**使用场景**：\n",
        "- 自定义日期时间标签\n",
        "- 使用文字标签代替数字\n",
        "- 调整刻度密度\n",
        "- 旋转长标签以避免重叠\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {},
      "outputs": [],
      "source": [
        "# 示例 7：自定义刻度位置和标签\n",
        "x = np.linspace(0, 10, 100)\n",
        "y = np.sin(x)\n",
        "\n",
        "fig, axes = plt.subplots(2, 2, figsize=(14, 10))\n",
        "\n",
        "# 1. 默认刻度\n",
        "axes[0, 0].plot(x, y, 'b-', linewidth=2)\n",
        "axes[0, 0].set_title('默认刻度', fontsize=12)\n",
        "axes[0, 0].grid(True, alpha=0.3)\n",
        "\n",
        "# 2. 自定义刻度位置\n",
        "axes[0, 1].plot(x, y, 'b-', linewidth=2)\n",
        "axes[0, 1].set_xticks([0, 2, 4, 6, 8, 10])\n",
        "axes[0, 1].set_yticks([-1, -0.5, 0, 0.5, 1])\n",
        "axes[0, 1].set_title('自定义刻度位置', fontsize=12)\n",
        "axes[0, 1].grid(True, alpha=0.3)\n",
        "\n",
        "# 3. 自定义刻度标签（文字标签）\n",
        "axes[1, 0].plot(x, y, 'b-', linewidth=2)\n",
        "axes[1, 0].set_xticks([0, 2.5, 5, 7.5, 10])\n",
        "axes[1, 0].set_xticklabels(['起点', '四分之一', '中点', '四分之三', '终点'])\n",
        "axes[1, 0].set_yticks([-1, 0, 1])\n",
        "axes[1, 0].set_yticklabels(['最小值', '零', '最大值'])\n",
        "axes[1, 0].set_title('自定义刻度标签（文字）', fontsize=12)\n",
        "axes[1, 0].grid(True, alpha=0.3)\n",
        "\n",
        "# 4. 旋转标签（适合长标签）\n",
        "categories = ['January', 'February', 'March', 'April', 'May', 'June']\n",
        "values = [23, 45, 56, 78, 13, 45]\n",
        "axes[1, 1].bar(categories, values, color='skyblue', edgecolor='navy', alpha=0.7)\n",
        "axes[1, 1].set_xticks(range(len(categories)))\n",
        "axes[1, 1].set_xticklabels(categories, rotation=45, ha='right')\n",
        "axes[1, 1].set_title('旋转标签（避免重叠）', fontsize=12)\n",
        "axes[1, 1].grid(True, alpha=0.3, axis='y')\n",
        "\n",
        "plt.tight_layout()\n",
        "plt.show()\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "### 2.4 plt.xlabel() 和 plt.ylabel()：设置坐标轴标签\n",
        "\n",
        "这两个函数用于设置 x 轴和 y 轴的标签文本。\n",
        "\n",
        "**语法格式**：\n",
        "```python\n",
        "plt.xlabel(label, fontsize=None, color=None, ...)\n",
        "plt.ylabel(label, fontsize=None, color=None, ...)\n",
        "```\n",
        "\n",
        "**参数说明**：\n",
        "- `label`: 标签文本（字符串）\n",
        "- `fontsize`: 字体大小（整数或字符串，如 'large', 'small'）\n",
        "- `color`: 标签颜色\n",
        "- `labelpad`: 标签与坐标轴的距离（像素）\n",
        "\n",
        "**使用场景**：\n",
        "- 说明坐标轴代表的物理量或变量\n",
        "- 添加单位信息\n",
        "- 提高图表的可读性\n",
        "\n",
        "**注意事项**：\n",
        "- 标签应该清晰、简洁\n",
        "- 如果变量有单位，应该在标签中包含单位\n",
        "- 可以使用 LaTeX 语法显示数学公式\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {},
      "outputs": [],
      "source": [
        "# 示例 8：设置坐标轴标签\n",
        "x = np.linspace(0, 10, 100)\n",
        "y = np.sin(x)\n",
        "\n",
        "fig, axes = plt.subplots(1, 3, figsize=(15, 4))\n",
        "\n",
        "# 1. 基础标签\n",
        "axes[0].plot(x, y, 'b-', linewidth=2)\n",
        "axes[0].set_xlabel('X 轴', fontsize=12)\n",
        "axes[0].set_ylabel('Y 轴', fontsize=12)\n",
        "axes[0].set_title('基础标签', fontsize=14)\n",
        "axes[0].grid(True, alpha=0.3)\n",
        "\n",
        "# 2. 带单位的标签\n",
        "time = np.linspace(0, 10, 100)\n",
        "temperature = 20 + 5 * np.sin(time) + np.random.normal(0, 0.5, 100)\n",
        "axes[1].plot(time, temperature, 'r-', linewidth=2, alpha=0.7)\n",
        "axes[1].set_xlabel('时间 (秒)', fontsize=12)\n",
        "axes[1].set_ylabel('温度 (°C)', fontsize=12)\n",
        "axes[1].set_title('带单位的标签', fontsize=14)\n",
        "axes[1].grid(True, alpha=0.3)\n",
        "\n",
        "# 3. 使用 LaTeX 数学公式\n",
        "x_math = np.linspace(0, 2*np.pi, 100)\n",
        "y_math = np.sin(x_math)\n",
        "axes[2].plot(x_math, y_math, 'g-', linewidth=2)\n",
        "axes[2].set_xlabel(r'角度 $\\theta$ (弧度)', fontsize=12)\n",
        "axes[2].set_ylabel(r'函数值 $f(\\theta) = \\sin(\\theta)$', fontsize=12)\n",
        "axes[2].set_title('LaTeX 数学公式标签', fontsize=14)\n",
        "axes[2].grid(True, alpha=0.3)\n",
        "\n",
        "plt.tight_layout()\n",
        "plt.show()\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "### 2.5 plt.title()：设置图表标题\n",
        "\n",
        "`plt.title()` 用于设置图表的标题。\n",
        "\n",
        "**语法格式**：\n",
        "```python\n",
        "plt.title(label, fontsize=None, color=None, loc='center', ...)\n",
        "```\n",
        "\n",
        "**参数说明**：\n",
        "- `label`: 标题文本（字符串）\n",
        "- `fontsize`: 字体大小\n",
        "- `color`: 标题颜色\n",
        "- `loc`: 标题位置（'left', 'center', 'right'）\n",
        "- `pad`: 标题与图表顶部的距离（像素）\n",
        "\n",
        "**使用场景**：\n",
        "- 说明图表的主题或内容\n",
        "- 提供图表的简要描述\n",
        "- 提高图表的可读性\n",
        "\n",
        "**注意事项**：\n",
        "- 标题应该简洁明了\n",
        "- 避免使用过长的标题\n",
        "- 可以使用多行标题（使用 `\\n` 换行）\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {},
      "outputs": [],
      "source": [
        "# 示例 9：设置图表标题\n",
        "x = np.linspace(0, 10, 100)\n",
        "y1 = np.sin(x)\n",
        "y2 = np.cos(x)\n",
        "\n",
        "fig, axes = plt.subplots(1, 3, figsize=(15, 4))\n",
        "\n",
        "# 1. 基础标题\n",
        "axes[0].plot(x, y1, 'b-', linewidth=2, label='sin(x)')\n",
        "axes[0].set_title('正弦函数', fontsize=14)\n",
        "axes[0].set_xlabel('X', fontsize=10)\n",
        "axes[0].set_ylabel('Y', fontsize=10)\n",
        "axes[0].grid(True, alpha=0.3)\n",
        "axes[0].legend()\n",
        "\n",
        "# 2. 多行标题\n",
        "axes[1].plot(x, y1, 'b-', linewidth=2, label='sin(x)')\n",
        "axes[1].plot(x, y2, 'r--', linewidth=2, label='cos(x)')\n",
        "axes[1].set_title('三角函数对比\\n正弦函数 vs 余弦函数', fontsize=14)\n",
        "axes[1].set_xlabel('X', fontsize=10)\n",
        "axes[1].set_ylabel('Y', fontsize=10)\n",
        "axes[1].grid(True, alpha=0.3)\n",
        "axes[1].legend()\n",
        "\n",
        "# 3. 不同位置的标题\n",
        "axes[2].plot(x, y1, 'b-', linewidth=2)\n",
        "axes[2].set_title('左对齐标题', fontsize=14, loc='left')\n",
        "axes[2].set_xlabel('X', fontsize=10)\n",
        "axes[2].set_ylabel('Y', fontsize=10)\n",
        "axes[2].grid(True, alpha=0.3)\n",
        "\n",
        "plt.tight_layout()\n",
        "plt.show()\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "### 2.6 plt.grid()：显示网格线\n",
        "\n",
        "`plt.grid()` 用于在图表中显示网格线，提高数据的可读性。\n",
        "\n",
        "**语法格式**：\n",
        "```python\n",
        "plt.grid(visible=True, which='major', axis='both', alpha=0.5, ...)\n",
        "```\n",
        "\n",
        "**参数说明**：\n",
        "- `visible`: 是否显示网格（True/False）\n",
        "- `which`: 显示哪些网格线（'major', 'minor', 'both'）\n",
        "- `axis`: 显示哪个轴的网格（'x', 'y', 'both'）\n",
        "- `alpha`: 透明度（0-1之间）\n",
        "- `linestyle`: 线型（'-', '--', '-.', ':'）\n",
        "- `linewidth`: 线宽\n",
        "- `color`: 网格线颜色\n",
        "\n",
        "**使用场景**：\n",
        "- 提高数据点的可读性\n",
        "- 帮助估算数值\n",
        "- 使图表更加专业\n",
        "\n",
        "**注意事项**：\n",
        "- 网格线应该足够淡，不能干扰主要数据\n",
        "- 通常使用 `alpha=0.3` 到 `0.5` 的透明度\n",
        "- 可以根据需要只显示某个方向的网格\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {},
      "outputs": [],
      "source": [
        "# 示例 10：网格线的不同样式\n",
        "x = np.linspace(0, 10, 100)\n",
        "y = np.sin(x)\n",
        "\n",
        "fig, axes = plt.subplots(2, 2, figsize=(12, 10))\n",
        "\n",
        "# 1. 无网格\n",
        "axes[0, 0].plot(x, y, 'b-', linewidth=2)\n",
        "axes[0, 0].set_title('无网格', fontsize=12)\n",
        "axes[0, 0].grid(False)\n",
        "\n",
        "# 2. 默认网格（两个方向）\n",
        "axes[0, 1].plot(x, y, 'b-', linewidth=2)\n",
        "axes[0, 1].set_title('默认网格（两个方向）', fontsize=12)\n",
        "axes[0, 1].grid(True, alpha=0.3)\n",
        "\n",
        "# 3. 只显示水平网格\n",
        "axes[1, 0].plot(x, y, 'b-', linewidth=2)\n",
        "axes[1, 0].set_title('只显示水平网格', fontsize=12)\n",
        "axes[1, 0].grid(True, axis='y', alpha=0.5, linestyle='--', color='gray')\n",
        "\n",
        "# 4. 自定义网格样式\n",
        "axes[1, 1].plot(x, y, 'b-', linewidth=2)\n",
        "axes[1, 1].set_title('自定义网格样式', fontsize=12)\n",
        "axes[1, 1].grid(True, alpha=0.4, linestyle=':', linewidth=0.8, color='red')\n",
        "\n",
        "plt.tight_layout()\n",
        "plt.show()\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## 第三部分：图例和标注\n",
        "\n",
        "图例和标注是图表中重要的说明性元素，帮助读者理解图表内容。\n",
        "\n",
        "### 3.1 plt.legend()：显示图例\n",
        "\n",
        "`plt.legend()` 用于显示图例，说明不同数据系列的含义。\n",
        "\n",
        "**语法格式**：\n",
        "```python\n",
        "plt.legend(loc='best', ncol=1, frameon=True, ...)\n",
        "```\n",
        "\n",
        "**参数说明**：\n",
        "- `loc`: 图例位置（字符串或数字）\n",
        "  - 字符串：'best', 'upper right', 'upper left', 'lower left', 'lower right', 'right', 'center left', 'center right', 'lower center', 'upper center', 'center'\n",
        "  - 数字：0-10 对应不同位置\n",
        "- `ncol`: 图例列数（默认为 1）\n",
        "- `frameon`: 是否显示图例边框（True/False）\n",
        "- `fancybox`: 是否使用圆角边框（True/False）\n",
        "- `shadow`: 是否显示阴影（True/False）\n",
        "- `fontsize`: 字体大小\n",
        "- `title`: 图例标题\n",
        "\n",
        "**前提条件**：\n",
        "- 绘图时必须使用 `label` 参数为数据系列添加标签\n",
        "- 例如：`plt.plot(x, y, label='数据系列1')`\n",
        "\n",
        "**使用场景**：\n",
        "- 多数据系列对比\n",
        "- 说明不同线条、标记的含义\n",
        "- 提高图表的可读性\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {},
      "outputs": [],
      "source": [
        "# 示例 11：图例的基本使用\n",
        "x = np.linspace(0, 10, 100)\n",
        "y1 = np.sin(x)\n",
        "y2 = np.cos(x)\n",
        "y3 = np.sin(x) * np.cos(x)\n",
        "\n",
        "plt.figure(figsize=(10, 6))\n",
        "plt.plot(x, y1, 'b-', linewidth=2, label='sin(x)')\n",
        "plt.plot(x, y2, 'r--', linewidth=2, label='cos(x)')\n",
        "plt.plot(x, y3, 'g-.', linewidth=2, label='sin(x) * cos(x)')\n",
        "plt.xlabel('X', fontsize=12)\n",
        "plt.ylabel('Y', fontsize=12)\n",
        "plt.title('图例示例', fontsize=14)\n",
        "plt.grid(True, alpha=0.3)\n",
        "plt.legend(fontsize=10, loc='best')  # 自动选择最佳位置\n",
        "plt.show()\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "### 3.2 label 参数：为数据系列添加标签\n",
        "\n",
        "在使用 `plt.plot()`, `plt.scatter()` 等绘图函数时，使用 `label` 参数为数据系列添加标签，这是显示图例的前提。\n",
        "\n",
        "**语法格式**：\n",
        "```python\n",
        "plt.plot(x, y, label='数据系列名称')\n",
        "```\n",
        "\n",
        "**注意事项**：\n",
        "- 每个数据系列都应该有唯一的标签\n",
        "- 标签应该清晰、简洁\n",
        "- 如果不需要图例，可以不设置 label\n",
        "\n",
        "**使用场景**：\n",
        "- 多数据系列对比\n",
        "- 不同实验条件的数据\n",
        "- 不同模型或方法的对比\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {},
      "outputs": [],
      "source": [
        "# 示例 12：不同图例位置和样式\n",
        "x = np.linspace(0, 10, 100)\n",
        "y1 = np.sin(x)\n",
        "y2 = np.cos(x)\n",
        "\n",
        "fig, axes = plt.subplots(2, 2, figsize=(14, 10))\n",
        "\n",
        "# 1. 右上角\n",
        "axes[0, 0].plot(x, y1, 'b-', linewidth=2, label='sin(x)')\n",
        "axes[0, 0].plot(x, y2, 'r--', linewidth=2, label='cos(x)')\n",
        "axes[0, 0].set_title('右上角 (upper right)', fontsize=12)\n",
        "axes[0, 0].grid(True, alpha=0.3)\n",
        "axes[0, 0].legend(loc='upper right', fontsize=10)\n",
        "\n",
        "# 2. 左下角\n",
        "axes[0, 1].plot(x, y1, 'b-', linewidth=2, label='sin(x)')\n",
        "axes[0, 1].plot(x, y2, 'r--', linewidth=2, label='cos(x)')\n",
        "axes[0, 1].set_title('左下角 (lower left)', fontsize=12)\n",
        "axes[0, 1].grid(True, alpha=0.3)\n",
        "axes[0, 1].legend(loc='lower left', fontsize=10)\n",
        "\n",
        "# 3. 多列图例\n",
        "axes[1, 0].plot(x, y1, 'b-', linewidth=2, label='sin(x)')\n",
        "axes[1, 0].plot(x, y2, 'r--', linewidth=2, label='cos(x)')\n",
        "axes[1, 0].set_title('多列图例 (ncol=2)', fontsize=12)\n",
        "axes[1, 0].grid(True, alpha=0.3)\n",
        "axes[1, 0].legend(loc='upper center', ncol=2, fontsize=10)\n",
        "\n",
        "# 4. 自定义样式（圆角、阴影）\n",
        "axes[1, 1].plot(x, y1, 'b-', linewidth=2, label='sin(x)')\n",
        "axes[1, 1].plot(x, y2, 'r--', linewidth=2, label='cos(x)')\n",
        "axes[1, 1].set_title('自定义样式（圆角、阴影）', fontsize=12)\n",
        "axes[1, 1].grid(True, alpha=0.3)\n",
        "axes[1, 1].legend(loc='best', fancybox=True, shadow=True, framealpha=0.9, fontsize=10)\n",
        "\n",
        "plt.tight_layout()\n",
        "plt.show()\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "### 3.3 plt.text()：添加文本标注\n",
        "\n",
        "`plt.text()` 用于在图表中的指定位置添加文本标注。\n",
        "\n",
        "**语法格式**：\n",
        "```python\n",
        "plt.text(x, y, s, fontsize=None, ha='left', va='bottom', ...)\n",
        "```\n",
        "\n",
        "**参数说明**：\n",
        "- `x, y`: 文本位置的坐标\n",
        "- `s`: 文本内容（字符串）\n",
        "- `fontsize`: 字体大小\n",
        "- `ha`: 水平对齐方式（'left', 'center', 'right'）\n",
        "- `va`: 垂直对齐方式（'bottom', 'center', 'top', 'baseline'）\n",
        "- `color`: 文本颜色\n",
        "- `bbox`: 文本框样式（字典，如 `{'boxstyle': 'round', 'facecolor': 'wheat', 'alpha': 0.5}`）\n",
        "- `rotation`: 文本旋转角度\n",
        "\n",
        "**坐标系统**：\n",
        "- 默认使用数据坐标系统\n",
        "- 可以使用 `transform` 参数切换到其他坐标系统\n",
        "\n",
        "**使用场景**：\n",
        "- 标注特殊数据点\n",
        "- 添加说明文字\n",
        "- 标记重要信息\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {},
      "outputs": [],
      "source": [
        "# 示例 13：文本标注的使用\n",
        "x = np.linspace(0, 10, 100)\n",
        "y = np.sin(x)\n",
        "\n",
        "plt.figure(figsize=(12, 6))\n",
        "plt.plot(x, y, 'b-', linewidth=2, label='sin(x)')\n",
        "plt.xlabel('X', fontsize=12)\n",
        "plt.ylabel('Y', fontsize=12)\n",
        "plt.title('文本标注示例', fontsize=14)\n",
        "plt.grid(True, alpha=0.3)\n",
        "\n",
        "# 1. 基础文本标注\n",
        "plt.text(2, 0.5, '这是一个标注点', fontsize=12, color='red')\n",
        "\n",
        "# 2. 带文本框的标注\n",
        "plt.text(5, -0.5, '带文本框的标注', fontsize=12, \n",
        "         bbox=dict(boxstyle='round', facecolor='wheat', alpha=0.5))\n",
        "\n",
        "# 3. 不同对齐方式的标注\n",
        "plt.text(8, 0.8, '右上对齐', fontsize=12, ha='right', va='top', color='green')\n",
        "plt.text(8, 0.8, '●', fontsize=20, ha='center', va='center', color='green')\n",
        "\n",
        "# 4. 旋转文本\n",
        "plt.text(1, -0.8, '旋转文本', fontsize=12, rotation=45, color='purple')\n",
        "\n",
        "# 5. 标注最大值点\n",
        "max_idx = np.argmax(y)\n",
        "max_x = x[max_idx]\n",
        "max_y = y[max_idx]\n",
        "plt.plot(max_x, max_y, 'ro', markersize=10)  # 标记点\n",
        "plt.text(max_x, max_y + 0.2, f'最大值: ({max_x:.2f}, {max_y:.2f})', \n",
        "         fontsize=11, ha='center', \n",
        "         bbox=dict(boxstyle='round,pad=0.5', facecolor='yellow', alpha=0.7))\n",
        "\n",
        "plt.legend()\n",
        "plt.show()\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "### 3.4 plt.annotate()：添加带箭头的注释\n",
        "\n",
        "`plt.annotate()` 用于添加带箭头的注释，比 `plt.text()` 更适合指向特定位置。\n",
        "\n",
        "**语法格式**：\n",
        "```python\n",
        "plt.annotate(text, xy, xytext=None, arrowprops=None, ...)\n",
        "```\n",
        "\n",
        "**参数说明**：\n",
        "- `text`: 注释文本（字符串）\n",
        "- `xy`: 箭头指向的位置（元组 (x, y)）\n",
        "- `xytext`: 文本位置（元组 (x, y)），如果为 None 则文本在 xy 位置\n",
        "- `arrowprops`: 箭头属性（字典）\n",
        "  - `arrowstyle`: 箭头样式（'->', '->', '-|>', '<-', '<->' 等）\n",
        "  - `color`: 箭头颜色\n",
        "  - `lw` 或 `linewidth`: 箭头线宽\n",
        "  - `shrink`: 箭头收缩比例\n",
        "- `fontsize`: 字体大小\n",
        "- `ha`, `va`: 对齐方式\n",
        "\n",
        "**常用箭头样式**：\n",
        "- `'->'`: 简单箭头\n",
        "- `'->'`: 粗箭头\n",
        "- `'-|>'`: 填充箭头\n",
        "- `'<->'`: 双向箭头\n",
        "- `'simple'`: 简单线条\n",
        "- `'fancy'`: 花式箭头\n",
        "\n",
        "**使用场景**：\n",
        "- 标注特殊数据点\n",
        "- 说明数据特征\n",
        "- 指向图表中的关键位置\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {},
      "outputs": [],
      "source": [
        "# 示例 14：带箭头的注释\n",
        "x = np.linspace(0, 10, 100)\n",
        "y = np.sin(x)\n",
        "\n",
        "plt.figure(figsize=(12, 6))\n",
        "plt.plot(x, y, 'b-', linewidth=2, label='sin(x)')\n",
        "plt.xlabel('X', fontsize=12)\n",
        "plt.ylabel('Y', fontsize=12)\n",
        "plt.title('带箭头的注释示例', fontsize=14)\n",
        "plt.grid(True, alpha=0.3)\n",
        "\n",
        "# 1. 基础箭头注释\n",
        "plt.annotate('最大值点', xy=(np.pi/2, 1), xytext=(2, 0.5),\n",
        "            arrowprops=dict(arrowstyle='->', color='red', lw=2),\n",
        "            fontsize=12, color='red')\n",
        "\n",
        "# 2. 填充箭头\n",
        "plt.annotate('最小值点', xy=(3*np.pi/2, -1), xytext=(8, -0.5),\n",
        "            arrowprops=dict(arrowstyle='->', color='green', lw=2, \n",
        "                          connectionstyle='arc3,rad=0.3'),\n",
        "            fontsize=12, color='green')\n",
        "\n",
        "# 3. 花式箭头\n",
        "plt.annotate('零点', xy=(np.pi, 0), xytext=(6, 0.8),\n",
        "            arrowprops=dict(arrowstyle='fancy', color='purple', lw=2,\n",
        "                          connectionstyle='arc3,rad=-0.3'),\n",
        "            fontsize=12, color='purple',\n",
        "            bbox=dict(boxstyle='round,pad=0.5', facecolor='yellow', alpha=0.7))\n",
        "\n",
        "# 4. 双向箭头\n",
        "plt.annotate('周期', xy=(0, 0), xytext=(2*np.pi, 0),\n",
        "            arrowprops=dict(arrowstyle='<->', color='orange', lw=2),\n",
        "            fontsize=12, color='orange', ha='center')\n",
        "\n",
        "plt.legend()\n",
        "plt.show()\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "### 3.5 图例位置控制：loc 参数详解\n",
        "\n",
        "`loc` 参数是 `plt.legend()` 中最重要的参数之一，用于控制图例的位置。\n",
        "\n",
        "**常用位置字符串**：\n",
        "- `'best'`: 自动选择最佳位置（避免遮挡数据）\n",
        "- `'upper right'`: 右上角\n",
        "- `'upper left'`: 左上角\n",
        "- `'lower left'`: 左下角\n",
        "- `'lower right'`: 右下角\n",
        "- `'right'`: 右侧居中\n",
        "- `'center left'`: 左侧居中\n",
        "- `'center right'`: 右侧居中\n",
        "- `'lower center'`: 底部居中\n",
        "- `'upper center'`: 顶部居中\n",
        "- `'center'`: 中心\n",
        "\n",
        "**数字代码**：\n",
        "- 0: 'best'\n",
        "- 1: 'upper right'\n",
        "- 2: 'upper left'\n",
        "- 3: 'lower left'\n",
        "- 4: 'lower right'\n",
        "- 5: 'right'\n",
        "- 6: 'center left'\n",
        "- 7: 'center right'\n",
        "- 8: 'lower center'\n",
        "- 9: 'upper center'\n",
        "- 10: 'center'\n",
        "\n",
        "**自定义位置**：\n",
        "- 可以使用元组 `(x, y)` 指定精确位置（0-1之间的相对坐标）\n",
        "- 例如：`loc=(0.5, 0.5)` 表示图形中心\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {},
      "outputs": [],
      "source": [
        "# 示例 15：所有图例位置展示\n",
        "x = np.linspace(0, 10, 100)\n",
        "y1 = np.sin(x)\n",
        "y2 = np.cos(x)\n",
        "\n",
        "# 创建所有位置的可视化\n",
        "positions = [\n",
        "    ('best', 0),\n",
        "    ('upper right', 1),\n",
        "    ('upper left', 2),\n",
        "    ('lower left', 3),\n",
        "    ('lower right', 4),\n",
        "    ('right', 5),\n",
        "    ('center left', 6),\n",
        "    ('center right', 7),\n",
        "    ('lower center', 8),\n",
        "    ('upper center', 9),\n",
        "    ('center', 10)\n",
        "]\n",
        "\n",
        "fig, axes = plt.subplots(3, 4, figsize=(16, 12))\n",
        "axes = axes.flatten()\n",
        "\n",
        "for i, (pos_name, pos_num) in enumerate(positions):\n",
        "    if i < len(axes):\n",
        "        ax = axes[i]\n",
        "        ax.plot(x, y1, 'b-', linewidth=1.5, label='sin(x)')\n",
        "        ax.plot(x, y2, 'r--', linewidth=1.5, label='cos(x)')\n",
        "        ax.set_title(f'loc=\"{pos_name}\" ({pos_num})', fontsize=10)\n",
        "        ax.grid(True, alpha=0.3)\n",
        "        ax.legend(loc=pos_name, fontsize=8)\n",
        "\n",
        "# 隐藏多余的子图\n",
        "for i in range(len(positions), len(axes)):\n",
        "    axes[i].axis('off')\n",
        "\n",
        "plt.tight_layout()\n",
        "plt.show()\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## 综合案例：完整的图表制作\n",
        "\n",
        "下面是一个综合案例，展示如何综合运用前面学到的所有知识点，创建一个专业的图表。\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {},
      "outputs": [],
      "source": [
        "# 综合案例：创建一个专业的科学图表\n",
        "# 模拟实验数据：不同温度下的反应速率\n",
        "\n",
        "# 1. 创建图形对象（设置大小、DPI、背景色）\n",
        "fig = plt.figure(figsize=(12, 8), dpi=100, facecolor='white', edgecolor='black')\n",
        "\n",
        "# 2. 准备数据\n",
        "temperature = np.linspace(20, 100, 50)  # 温度范围：20-100°C\n",
        "rate1 = 0.5 * np.exp(0.05 * (temperature - 20)) + np.random.normal(0, 0.1, 50)  # 反应1\n",
        "rate2 = 0.3 * np.exp(0.04 * (temperature - 20)) + np.random.normal(0, 0.08, 50)  # 反应2\n",
        "rate3 = 0.4 * np.exp(0.045 * (temperature - 20)) + np.random.normal(0, 0.09, 50)  # 反应3\n",
        "\n",
        "# 3. 绘制数据\n",
        "plt.plot(temperature, rate1, 'b-o', linewidth=2, markersize=6, \n",
        "         label='反应类型 A', alpha=0.8)\n",
        "plt.plot(temperature, rate2, 'r-s', linewidth=2, markersize=6, \n",
        "         label='反应类型 B', alpha=0.8)\n",
        "plt.plot(temperature, rate3, 'g-^', linewidth=2, markersize=6, \n",
        "         label='反应类型 C', alpha=0.8)\n",
        "\n",
        "# 4. 设置坐标轴范围\n",
        "plt.xlim(15, 105)\n",
        "plt.ylim(0, max(max(rate1), max(rate2), max(rate3)) * 1.1)\n",
        "\n",
        "# 5. 设置坐标轴标签\n",
        "plt.xlabel('温度 (°C)', fontsize=14, fontweight='bold')\n",
        "plt.ylabel('反应速率 (mol/L·s)', fontsize=14, fontweight='bold')\n",
        "\n",
        "# 6. 设置标题\n",
        "plt.title('不同反应类型在不同温度下的反应速率对比', \n",
        "          fontsize=16, fontweight='bold', pad=20)\n",
        "\n",
        "# 7. 设置刻度\n",
        "plt.xticks(np.arange(20, 105, 10), fontsize=11)\n",
        "plt.yticks(fontsize=11)\n",
        "\n",
        "# 8. 显示网格\n",
        "plt.grid(True, alpha=0.3, linestyle='--', linewidth=0.8)\n",
        "\n",
        "# 9. 显示图例\n",
        "plt.legend(loc='upper left', fontsize=12, frameon=True, \n",
        "          fancybox=True, shadow=True, framealpha=0.9)\n",
        "\n",
        "# 10. 添加文本标注\n",
        "plt.text(25, max(rate1) * 0.9, '低温区域', fontsize=11, \n",
        "         bbox=dict(boxstyle='round', facecolor='lightblue', alpha=0.7))\n",
        "plt.text(75, max(rate1) * 0.9, '高温区域', fontsize=11,\n",
        "         bbox=dict(boxstyle='round', facecolor='lightcoral', alpha=0.7))\n",
        "\n",
        "# 11. 添加箭头注释（标注最佳反应温度）\n",
        "max_rate1_idx = np.argmax(rate1)\n",
        "best_temp = temperature[max_rate1_idx]\n",
        "best_rate = rate1[max_rate1_idx]\n",
        "\n",
        "plt.annotate(f'最佳温度: {best_temp:.1f}°C', \n",
        "            xy=(best_temp, best_rate), \n",
        "            xytext=(best_temp + 15, best_rate - 0.5),\n",
        "            arrowprops=dict(arrowstyle='->', color='blue', lw=2,\n",
        "                          connectionstyle='arc3,rad=0.2'),\n",
        "            fontsize=11, color='blue',\n",
        "            bbox=dict(boxstyle='round,pad=0.5', facecolor='yellow', alpha=0.8))\n",
        "\n",
        "# 12. 调整布局\n",
        "plt.tight_layout()\n",
        "\n",
        "# 13. 显示图形\n",
        "plt.show()\n",
        "\n",
        "print(\"图表创建完成！\")\n",
        "print(f\"图形大小: {fig.get_size_inches()}\")\n",
        "print(f\"DPI: {fig.dpi}\")\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## 总结\n",
        "\n",
        "本教程详细讲解了 Matplotlib 中图形和坐标轴的基础操作，包括：\n",
        "\n",
        "### 第一部分：创建图形对象\n",
        "- ✅ `plt.figure()` 创建新图形\n",
        "- ✅ `figsize` 参数设置图形大小\n",
        "- ✅ `dpi` 参数设置分辨率\n",
        "- ✅ `facecolor` 和 `edgecolor` 设置背景色和边框色\n",
        "\n",
        "### 第二部分：坐标轴操作\n",
        "- ✅ `plt.xlim()` 和 `plt.ylim()` 设置坐标轴范围\n",
        "- ✅ `plt.axis()` 一次性设置 x 和 y 轴范围\n",
        "- ✅ `plt.xticks()` 和 `plt.yticks()` 设置刻度位置和标签\n",
        "- ✅ `plt.xlabel()` 和 `plt.ylabel()` 设置坐标轴标签\n",
        "- ✅ `plt.title()` 设置图表标题\n",
        "- ✅ `plt.grid()` 显示网格线\n",
        "\n",
        "### 第三部分：图例和标注\n",
        "- ✅ `plt.legend()` 显示图例\n",
        "- ✅ `label` 参数为数据系列添加标签\n",
        "- ✅ `plt.text()` 添加文本标注\n",
        "- ✅ `plt.annotate()` 添加带箭头的注释\n",
        "- ✅ 图例位置控制：`loc` 参数\n",
        "\n",
        "### 学习建议\n",
        "\n",
        "1. **实践为主**：每学习一个知识点，立即编写代码实践\n",
        "2. **参数探索**：尝试修改不同的参数值，观察效果变化\n",
        "3. **组合使用**：将多个知识点组合使用，创建更复杂的图表\n",
        "4. **参考文档**：遇到问题时查阅官方文档：https://matplotlib.org/stable/\n",
        "\n",
        "### 下一步学习\n",
        "\n",
        "掌握了图形和坐标轴基础后，可以继续学习：\n",
        "- 基本图表类型（线图、散点图、柱状图等）\n",
        "- 子图和布局\n",
        "- 样式和美化\n",
        "- 高级功能\n",
        "\n",
        "祝学习愉快！🎉\n"
      ]
    }
  ],
  "metadata": {
    "language_info": {
      "name": "python"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 2
}
